﻿



CREATE PROCEDURE [dbo].[proc_ProjectInterfaceSet_GetList]
	(
		@CompanyId int
	)
AS
	declare @count int
	set @count = (select count(id) from ProjectInterfaceSet Where companyid=@companyid)
	if(@count = 0)
		begin
			insert into ProjectInterfaceSet (ProductId,CId,CateOneId,CateTwoId,Title,CostPrice,SalePrice,Description,Sort,CompanyId) 
			select Id,CId,CateOneId,CateTwoId,Title,CostPrice,SalePrice,Description,Sort,@CompanyId from Product
		end
	
	select 
	Id,
	CateOneId,
	(select pc.title from product_category pc where pc.id=CateOneId) as CateOneName,
	CateTwoId,
	(select pc.title from product_category pc where pc.id=CateTwoId) as CateTwoName,
	(select pc.title from Product_Category pc where pc.id=ProjectInterfaceSet.cid) as CategoryName,
	Title,
	CostPrice,
	SalePrice,
	Description,
	Sort,
	CompanyId,
	IsNull(DepartmentId,0) as DepartmentId,
	(select Top 1 d.dname from department d where d.id = ProjectInterfaceSet.departmentid) as DepartmentName,
	(select Top 1 e.ename from employee e where e.username=ProjectInterfaceSet.username) as UserName,
(Select CompanyName From [Company] Where [Company].id = ProjectInterfaceSet.ExCompanyId) As ExCompanyName,
IsNull(ExCompanyId,CompanyId) As ExCompanyId
	from ProjectInterfaceSet 
	where
	 CompanyId=@CompanyId
	order by cateoneid asc,catetwoid asc
	
	RETURN



